package com.gxa.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Query;
import com.gxa.modules.sys.entity.User;
import com.gxa.modules.sys.entity.UserBak;
import com.gxa.modules.sys.mapper.UserMapper;
import com.gxa.modules.sys.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User queryByUsername(String username) {
        User user = baseMapper.selectOne(new QueryWrapper<User>().eq("username", username));
        return user;
    }


    @Override
    public PageUtils queryById(Map<String, Object> params) {
        String id = (String)params.get("id");
        IPage<User> page = this.page(new Query<User>().getPage(params),
                new QueryWrapper<User>().eq(StringUtils.isNotEmpty(id),"id",id)
                );
        return new PageUtils(page);
    }

    @Override
    public void updateUser(User user) {
        this.userMapper.updateUser(user);
    }

    @Override
    public Set<String> queryPerm(int id) {
        Set<String> perms = this.userMapper.queryPerm(id);
        return perms;
    }

    @Override
    public List<UserBak> getUserByName(String userName) {
        List<UserBak> user = this.userMapper.getUserByName(userName);
        return user;
    }


}
